import Vue from 'vue';
import Router from 'vue-router';
import store from '@/store'

Vue.use(Router);
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

import { commonRoutes } from './routerGroup'

const createRouter = () => new Router({
    // mode: 'history',
    // base: process.env.BASE_URL,
    mode: 'hash',
    base: '/',
    // 配置二级菜单路由组件
    routes: [
        ...commonRoutes,
        {
            path: '/login',
            component: () =>
                import ( /* webpackChunkName: "login" */ '@/components/page/Login/Login.vue'),
            meta: {
                title: '登录',
                requireAuth: false,
                keepAlive: false
            },
            name: 'Login'
        },
        // { path: '*', redirect: '/404' }
    ]
});

// setTimeout(() => {
//     function generateRoutes(data) {
//         console.log(data)
//         var result = []
//         data.forEach(item => {
//                 if (item.permissions) {
//                     item.permissions.forEach(item_ => {
//                         if (asyncRoutes[item_.name]) result.push(asyncRoutes[item_.name])
//                     })
//                 }
//             })
//             // console.log(result)
//             // 最后添加404页面 否则会在登陆成功后跳到404页面
//         result.push({ path: '*', redirect: '/404' }, )
//         return result
//     }
//     const routes = generateRoutes(store.getters.sidebarData)
//     console.log(routes)


// }, 4000)


// router.addRoutes([{
//     // 一级路由组件
//     path: '/',
//     // redirect: '/quku/survey',
//     component: () =>
//         import ( /* webpackChunkName: "home" */ '@/components/common/Home.vue'),
//     meta: { title: '自述文件' },
//     // 二级路由组件
//     children: [
//         // ...routes,
//         {
//             path: '/song/info',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/SongInfo/SongInfo.vue'),
//             meta: {
//                 title: '歌曲信息',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'SongInfo'
//         },
//         {
//             path: '/song/checked',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/QukuSong/SongChecked.vue'),
//             meta: {
//                 title: '歌曲审核',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'SongChecked'
//         },

//         {
//             path: '/singer_/edit',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/SingerInfo/SingerInfo.vue'),
//             meta: {
//                 title: '歌手信息',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'SingerInfo'
//         },

//         {
//             path: '/singer_/add',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/QukuArtist/AddSinger.vue'),
//             meta: {
//                 title: '新增歌手',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AddSinger'
//         },
//         {
//             path: '/singer_/checked',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/QukuArtist/SingerChecked.vue'),
//             meta: {
//                 title: '歌手审核',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'SingerChecked'
//         },

//         {
//             path: '/album_3/info_2',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/AlbumInfo_2/AlbumInfo_2.vue'),
//             meta: {
//                 title: '专辑信息_2',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AlbumInfo_2'
//         },
//         {
//             path: '/album_3/checked',
//             component: () =>
//                 import ( /* webpackChunkName: "qukumanage" */ '@/components/page/QukuManage/QukuAlbum/AlbumChecked.vue'),
//             meta: {
//                 title: '专辑审核',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AlbumChecked'
//         },
//         {
//             path: '/edit/menu_1',
//             component: () =>
//                 import ( /* webpackChunkName: "editmanage" */ '@/components/page/EditManage/EditMenu_1/EditMenu_1.vue'),
//             meta: {
//                 title: '编辑歌单&审核歌单',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditMenu_1'
//         },

//         {
//             path: '/radio/menu_1',
//             component: () =>
//                 import ( /* webpackChunkName: "editmanage" */ '@/components/page/EditManage/EditRadioStation/EditMenu_1.vue'),
//             meta: {
//                 title: '编辑电台&审核电台',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditMenu_1'
//         },

//         {
//             path: '/ranking/menu_1',
//             component: () =>
//                 import ( /* webpackChunkName: "editmanage" */ '@/components/page/EditManage/EditRankingList/EditMenu_1.vue'),
//             meta: {
//                 title: '编辑榜单&审核榜单',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditMenu_1'
//         },


//         {
//             path: '/label/level1/label',
//             component: () =>
//                 import ( /* webpackChunkName: "labelmanage" */ '@/components/page/LabelManage/EditLevel1Label/EditLevel1Label.vue'),
//             meta: {
//                 title: '二级标签',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditLevel1Label'
//         },
//         {
//             path: '/label/level2/label',
//             component: () =>
//                 import ( /* webpackChunkName: "labelmanage" */ '@/components/page/LabelManage/EditLevel2Label/EditLevel2Label.vue'),
//             meta: {
//                 title: '三级标签',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditLevel2Label'
//         },
//         {
//             path: '/label/level3/label',
//             component: () =>
//                 import ( /* webpackChunkName: "labelmanage" */ '@/components/page/LabelManage/EditLevel3Label/EditLevel3Label.vue'),
//             meta: {
//                 title: '四级标签',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditLevel3Label'
//         },
//         {
//             path: '/label/level4/label',
//             component: () =>
//                 import ( /* webpackChunkName: "labelmanage" */ '@/components/page/LabelManage/EditLevel4Label/EditLevel4Label.vue'),
//             meta: {
//                 title: '五级标签',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditLevel4Label'
//         },
//         {
//             path: '/label/level5/label',
//             component: () =>
//                 import ( /* webpackChunkName: "labelmanage" */ '@/components/page/LabelManage/EditLevel5Label/EditLevel5Label.vue'),
//             meta: {
//                 title: '六级标签',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'EditLevel5Label'
//         },

//         {
//             path: '/batch_/search',
//             component: () =>
//                 import ( /* webpackChunkName: "modifymanage" */ '@/components/page/BatchManage/BatchSearch.vue'),
//             meta: {
//                 title: '批量查询',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'BatchSearch'
//         },

//         {
//             path: '/channel/add',
//             component: () =>
//                 import ( /* webpackChunkName: "channelmanage" */ '@/components/page/ChannelManage/ChannelList/AddChannelList.vue'),
//             meta: {
//                 title: '新增渠道',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AddChannel'
//         },


//         {
//             path: '/add_/user',
//             component: () =>
//                 import ( /* webpackChunkName: "channelmanage" */ '@/components/page/ChannelManage/AddUser/AddUser.vue'),
//             meta: {
//                 title: '新增用户',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AddUser'

//         },

//         {
//             path: '/cp/copyright',
//             component: () =>
//                 import ( /* webpackChunkName: "copyrightmanage" */ '@/components/page/CopyrightManage/AddCopyright/AddCopyright.vue'),
//             meta: {
//                 title: '新增CP',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AddCopyright'
//         },

//         {
//             path: '/warehouse_/app',
//             component: () =>
//                 import ( /* webpackChunkName: "copyrightmanage" */ '@/components/page/CopyrightManage/WarehouseApp/WarehouseApp.vue'),
//             meta: {
//                 title: '入库申请',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'WarehouseApp'
//         },
//         {
//             path: '/warehouse_/details',
//             component: () =>
//                 import ( /* webpackChunkName: "copyrightmanage" */ '@/components/page/CopyrightManage/AuditDetails/AuditDetails.vue'),
//             meta: {
//                 title: '审核详情',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AuditDetails'
//         },
//         {
//             path: '/warehouse_/edit',
//             component: () =>
//                 import ( /* webpackChunkName: "copyrightmanage" */ '@/components/page/CopyrightManage/AuditDetails/AuditEdit.vue'),
//             meta: {
//                 title: '审核编辑',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'AuditEdit'
//         },

//         {
//             path: '/song_1/detail',
//             component: () =>
//                 import ( /* webpackChunkName: "copyrightmanage" */ '@/components/page/CopyrightManage/SongDetail/SongDetail.vue'),
//             meta: {
//                 title: '歌曲详情',
//                 requireAuth: true,
//                 keepAlive: true
//             },
//             name: 'SongDetail'
//         },

//         {
//             path: '/404',
//             component: () =>
//                 import ( /* webpackChunkName: "404" */ '@/components/page/common/404.vue'),
//             meta: { title: '404' }
//         },
//     ]
// }, ])

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}
export default router;